package com.nanhai.buddhist.college.module.collegebase.controller.teacher.teacher;


import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.operatelog.core.annotations.OperateLog;
import com.nanhai.buddhist.college.module.collegebase.api.collegeclass.dto.ClassesInfoDTO;
import com.nanhai.buddhist.college.module.collegebase.api.collegeclass.vo.ClassesInfoDTOPageVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.teacherteachers.vo.TeacherTeachersRespVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.teacherteachers.vo.TeacherTeachersUpdateReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.teacher.teacher.vo.AuthLoginReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.teacher.teacher.vo.AuthLoginRespVO;
import com.nanhai.buddhist.college.module.collegebase.convert.classes.ClassesConvert;
import com.nanhai.buddhist.college.module.collegebase.convert.teacherteachers.TeacherTeachersConvert;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.classes.ClassesDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.teacherteachers.TeacherTeachersDO;
import com.nanhai.buddhist.college.module.collegebase.service.classes.ClassesService;
import com.nanhai.buddhist.college.module.collegebase.service.teacherteachers.TeacherAuthService;
import com.nanhai.buddhist.college.module.collegebase.service.teacherteachers.TeacherTeachersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import java.util.List;

import static com.nanhai.buddhist.college.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 - 教师管理 - 认证")
@RestController
@RequestMapping("/collegebase/teacher-teachers")
@Validated
public class TeacherAuthController {

    @Resource
    private TeacherTeachersService teacherTeachersService;

    @Resource
    private ClassesService classesService;

/*
    @PostMapping("/login")
    @PermitAll
    @ApiOperation("使用账号密码登录")
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    public CommonResult<AuthLoginRespVO> login(@RequestBody @Valid AuthLoginReqVO reqVO) {
        return success(teacherAuthService.login(reqVO));
    }*/

    @PutMapping("/update")
    @ApiOperation("修改个人信息")
    public CommonResult<Boolean> updateTeacherTeachers(@Valid @RequestBody TeacherTeachersUpdateReqVO updateReqVO) {
        teacherTeachersService.updateTeacherTeachers(updateReqVO);
        return success(true);
    }



    @GetMapping("/get")
    @ApiOperation("查看个人信息")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    public CommonResult<TeacherTeachersRespVO> getTeacherTeachers(@RequestParam("id") String id) {
        TeacherTeachersDO teacherTeachers = teacherTeachersService.getTeacherTeachers(id);
        return success(TeacherTeachersConvert.INSTANCE.convert(teacherTeachers));
    }

    @GetMapping("/byTeacher/List")
    @ApiOperation("根据教师id获取班级列表（分页）")
    public CommonResult<PageResult<ClassesInfoDTO>> getClassesInfoDTOPageByTeacher(ClassesInfoDTOPageVO req) {
        PageResult<ClassesDO> pageResult = classesService.getClassesInfoDTOPageByTeacher(req);
        return CommonResult.success(ClassesConvert.INSTANCE.convertClassesInfoDTOPage(pageResult));
    }

    @GetMapping("/byFindStr/list")
    @ApiOperation("获得教师列表--可以根据昵称模糊查询")
    @ApiImplicitParam(name = "findStr", value = "查询条件", required = true, example = "1024,2048", dataTypeClass = String.class)
    public CommonResult<List<TeacherTeachersRespVO>> getTeacherTeachersDOListByStr(String findStr) {
        List<TeacherTeachersDO> list = teacherTeachersService.getTeacherTeachersDOListByStr(findStr);
        return success(TeacherTeachersConvert.INSTANCE.convertList(list));
    }


}
